package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kmproject.haifu.app.utils.ShapeFactoryUtils;
import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.User;
import com.kmproject.haifu.mvp.ui.widget.CircleImageView;
import com.luliang.shapeutils.DevShapeUtils;

import java.util.List;

import com.kmproject.haifu.R;


public class NewUserAdapter extends BaseQuickAdapter<User,BaseViewHolder> {
    public NewUserAdapter(@Nullable List<User> data) {
        super(R.layout.user_item,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, User item) {

        helper.setText(R.id.user_item_name_txt,item.getUsername()+"("+item.getNikName()+")")
                .setText(R.id.user_item_age_txt,item.getGender()+"  "+item.getUserAge()+"岁"+"  "+item.getIndustry()+"  "+item.getCompany())
                .setText(R.id.user_item_time_txt,"创建时间:"+item.getRegistTime());
        DevShapeUtils.selectorPressed(ShapeFactoryUtils.rectAngleCornor4AndLineColorDrawable(R.color.ehome_selected,R.color.ehome_selected),ShapeFactoryUtils.rectAngleCornor4AndLineColorDrawable(R.color.white,R.color.white))
                .into(helper.<LinearLayout>getView(R.id.user_item_lay));
        if (item.getHeadImg()!=null&&item.getHeadImg().length()>10)
        {
            Glide.with(mContext)
                    .load(Api.APP_img+item.getHeadImg())
                    .into(helper.<CircleImageView>getView(R.id.user_item_headimg_img));
        }
    }

    /**
     * 删除用户刷新界面
     * @param index
     */
    public void  del(int index)
    {
        if (getData().size()>0)
        {
            getData().remove(index);
            notifyDataSetChanged();
        }
    }
}
